package tables

import (
	"peilian-api/app/global/variable"

	"gorm.io/gorm"
)

type Interview struct {
	gorm.Model
	Type      uint   `gorm:"type:tinyint(1);not null;comment:类型,1:河北招聘网"`
	UserId    uint   `gorm:"type:uint;not null;comment:用户id"`
	UserName  string `gorm:"type:varchar(2048);comment:意见反馈内容"`
	Phone     string `gorm:"type:varchar(13);comment:电话号码"`
	SessionId uint   `gorm:"type:uint;comment:面试场次id"`
}

func (Interview) TableName() string {
	return "interview"
}

func (f *Interview) InsertInterview(itw Interview) error {
	if d := variable.DB.MySQL.Model(f).Save(&itw); d.Error != nil {
		return d.Error
	}
	return nil
}

// 根据session 查询用户名
func (f *Interview) GetInterview(sessionId int) (Interview, error) {
	var i Interview
	d := variable.DB.MySQL.Model(f).Where("id = ?", sessionId).Find(&i)
	if d.Error != nil {
		return i, d.Error
	}
	return i, nil
}
